<?php

namespace app\common\model\xilujob;

use think\Cache;
use think\Model;


class WorkExperience extends Model
{

    

    

    // 表名
    protected $name = 'xilujob_work_experience';
    const CACHE_KEY = 'work_experience_options';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];

    public static function getAll() {
        $cacheKey = self::CACHE_KEY;
        $all = Cache::get($cacheKey);
        if(!$all) {
            $all = static::order('weigh')->select();
            Cache::set($cacheKey, $all, 3600);
        }
        return $all;
    }

    public static function getnameById($id){
        if(!$id) return '';
        $all = self::getAll();
        if(!$all) return '';
        $all = array_column(collection($all)->toArray(),'name','id');
        return isset($all[$id])? $all[$id] : '';
    }


}
